#!/usr/bin/python3
"""
configure pacman
"""
import os
import sys

import osbuild.api


SCHEMA = """
"additionalProperties": false,
"properties": {
  "architecture": {
    "type": "string",
    "description": "pacman architecture",
    "default": "x86_64"
  }
}
"""


def main(tree, options):
    arch = options.get("architecture", "x86_64")
    cfg = f"""
[options]
Architecture = {arch}
SigLevel    = Required DatabaseOptional
LocalFileSigLevel = Optional
"""
    os.makedirs(os.path.join(tree, "etc"), exist_ok=True)
    cfgpath = os.path.join(tree, "etc", "pacman.conf")
    with open(cfgpath, "w", encoding="utf-8") as cfgfile:
        cfgfile.write(cfg)

    return 0


if __name__ == '__main__':
    args = osbuild.api.arguments()
    r = main(args["tree"], args["options"])
    sys.exit(r)
